package com.dz.service.impl;

import com.dz.bean.Guide;
import com.dz.mapper.GuideDao;
import com.dz.service.GuideService;
import com.dz.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GuideServiceImpl implements GuideService {

    @Autowired
    GuideDao guideDao;

    @Override
    public Guide add(Guide guide) {
        guideDao.add(guide);
        Guide result = guideDao.findById(guide.getId());
        return result;
    }

    @Override
    public int delete(Integer id) {
        return guideDao.delete(id);
    }

    @Override
    public Guide edit(Guide guide) {
        guideDao.edit(guide);
        Guide result = guideDao.findById(guide.getId());
        return result;
    }

    @Override
    public List<Guide> all(Guide guide) {
        return guideDao.all(guide);
    }

    @Override
    public Guide findById(Integer id) {
        return guideDao.findById(id);
    }


    public void page(Page page, Guide guide) {
        int totalCount = guideDao.pageCount(guide);
        //System.out.println( "----------"+totalCount);
        Object data = guideDao.page(page,guide);
        //System.out.println( "----------"+data);
        page.setTotalCount(totalCount);
        page.setData(data);
    }

    public Guide getByUsername(String username) {
        return guideDao.getByUsername(username);
    }

    public Guide getByPhone(String phone) {
        return guideDao.getByPhone(phone);
    }
}
